unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,Class_Unit,System.Rtti,
  Helpr_Unit;

type
  TViewFind=class(TPersistent)
  public
  end;
  TForm1 = class(TForm)
    Btnx_1: TButton;
    Btnx_2: TButton;
    Btnx_3: TButton;
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
    procedure Btnx_3Click(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

uses
  qjson,class_KzDebug;

{$R *.dfm}

procedure TForm1.Btnx_1Click(Sender: TObject);
var
  QJSON:TQJson;
  UNITX:TUNIT;
  UNITY:TUNIT;
  VALUE:string;
begin
  QJSON:=TQJson.Create;

  UNITX:=TUNIT.Create;
  UNITX.UNITLINK:='0001-0001';
  UNITX.SUBJLINK:='0001,0002,0003';
  UNITX.UNITNAME:='kazarus';

  QJSON.FromRtti(UNITX);
  VALUE:=QJSON.ToString;
  ShowMessage(VALUE);

  UNITY:=TUNIT.Create;
  QJSON.ToRtti(UNITY);
  ShowMessage(UNITY.SUBJLINK);
end;

procedure TForm1.Btnx_2Click(Sender: TObject);
var
  R: TRttiContext;
  T: TRttiType;
  P: TRttiProperty;
  C: TCustomAttribute;
  F: TRttiField;
  M: TRttiMethod;

  UnitX:TUNIT;
begin
  try
    T := R.GetType(TUNIT);

    M:=T.GetMethod('selectdb');
    if M<>nil then
    begin
      ShowMessage('method is existed.');
      if m.IsClassMethod then
      begin
        ShowMessage('method is classmethold');
      end;
      m.Invoke(TUNIT,['value']);
      TUNIT.SelectDB('value');
    end;

    for C in T.GetAttributes do
    begin
      ShowMessage(C.ToString);
    end;

    for F in T.GetFields do
    begin
      KzDebug.FileFmt('%S:%S',['field',F.Name]);
    end;

    for M in T.GetMethods do
    begin
      KzDebug.FileFmt('%S:%S',['method',M.Name]);
    end;
  finally
  end;
end;

procedure TForm1.Btnx_3Click(Sender: TObject);
var
  R: TRttiContext;
  T: TRttiType;
  M: TRttiMethod;
begin
  T := R.GetType(TypeInfo(THelprUnit));
  M := T.GetMethod('selectdb');
  M.Invoke(TUNIT,['value']);
end;

end.
